package com.bjzsly.star3.xyh.wxapi;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;

import com.bjzsly.star3.xyh.auth.TxShareUtils;
import com.bjzsly.star3.xyh.utils.ToastUtils;
import com.tencent.mm.opensdk.constants.ConstantsAPI;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;


public class WXEntryActivity extends Activity implements IWXAPIEventHandler {


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        TxShareUtils.getInstance().onHandleIntent(getIntent(), this);
    }

    @Override
    protected void onStart() {
        super.onStart();

    }

    @Override
    public void onReq(BaseReq req) {
        switch (req.getType()) {
            case ConstantsAPI.COMMAND_GETMESSAGE_FROM_WX:
//                goToGetMsg();
                break;
            case ConstantsAPI.COMMAND_SHOWMESSAGE_FROM_WX:
//                goToShowMsg((ShowMessageFromWX.Req) req);
                break;
            default:
                break;
        }
    }

    @Override
    public void onResp(BaseResp resp) {
        switch (resp.errCode) {
            case BaseResp.ErrCode.ERR_OK:
                if (resp.getType() == 1) {
                    ToastUtils.showToast("type=1");
//                    String code = ((SendAuth.Resp) resp).code;
//                    LoginManager.getInstance().loginWx(code);
                } else if (resp.getType() == 2) {
                    ToastUtils.showToast("分享成功");
                }
                break;
            case BaseResp.ErrCode.ERR_USER_CANCEL:
                ToastUtils.showToast("用户取消");
                break;
            case BaseResp.ErrCode.ERR_AUTH_DENIED:
                ToastUtils.showToast("授权被拒绝");
                break;
            case BaseResp.ErrCode.ERR_UNSUPPORT:
                ToastUtils.showToast("分享失败");
                break;
            default:
                break;
        }
        finish();
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        TxShareUtils.getInstance().onHandleIntent(intent, this);
    }
}
